// HudLayer.js
//

var HudLayer = cc.Layer.extend({
	_winSize: null,
	_pCenter: null,
	_delegate: null,

	mJoypad: null,
	mAttack: null,
	mAttackA: null,
	mAttackB: null,
	ctor:function(){
		this._super();
		_winSize = cc.Director.getInstance().getWinSize();
		_pCenter = cc.p(_winSize.width / 2, _winSize.height / 2);
	},
	init:function(){
		var bRet = false;

		if(this._super()){

			// 添加控制器
			this.mJoypad = Joypad.create();
			this.addChild(this.mJoypad);

			var keyMap = KeyMap.create();
			keyMap.setDelegateJoypad(this.mJoypad);
			keyMap.setDelegateAttack(this);
			this.addChild(keyMap);

			// 添加攻击按钮

			//this.mAttack = AttackButton.initWithImage(s_Attack);
			//this.mAttack.setPosition(cc.p(mWinSize.width - 80,  80));
			//this.mAttack.setDelegate(this);
			//this.mAttack.setAttackType(AT.ATTACK);
			//this.addChild(this.mAttack);
			if (sys["capabilities"].hasOwnProperty('keyboard'))
			{
				cc.log("enable keyboard")
				this.setKeyboardEnabled(true);
			}
				
			bRet = true;
		}
		return bRet;
	},
	setDelegate: function(delegate){
		this._delegate = delegate;
		this.mJoypad.setDelegate(delegate);
	},
	
	attackButtonClick:function(button){
		if (this._delegate){
			this._delegate.attackButtonClick(button);
		}
	},
	keyAttack:function(btnType){
		return
		if (btnType == AT.ATTACK_A && this.mAttackA.isCanClick())
			this.mAttackA.click();
		if (btnType == AT.ATTACK_B && this.mAttackB.isCanClick())
			this.mAttackB.click();
		if (btnType == AT.ATTACK && this.mAttack.isCanClick())
			this.mAttack.click();
		
		// this.attackButtonClick(bunType);
	},
	keyAttackUp:function(btnType){
		return 
		if (btnType == AT.ATTACK) //  && this.mAttack.isCanClick())
			this.mAttack.clickUp();		
	}
});

HudLayer.create = function(){
	var hudlayer = new HudLayer();
	if (hudlayer && hudlayer.init()){
		return hudlayer;
	}
	return null;
};


